import request from "./http";

//获取分类列表
function getClassification(pageNum,pageSize) {
    const url =`/api/api/cms/category/open/list`;
    const params = new URLSearchParams();
    params.append("pageNum",pageNum);
    params.append("pageSize",pageSize);
    return request.post(url,params)

}
//请求新闻类列表
function newsClassList(pageNum,pageSize) {
    const url = '/api/api/cms/category/open/list'
    return request.post(url,{pageNum:pageNum,pageSize:pageSize})
}

//获取新闻列表
function newsList(pageNum,pageSize,categoryId) {
    const url = '/api/api/cms/article/open/list'
    return request.post(url,{pageNum:pageNum,pageSize:pageSize,categoryId})
}
//轮播图列表
function shufflingFigure(pageNum, pageSize) {
    const parmas = new URLSearchParams();

    parmas.append("pageNum", pageNum);
    parmas.append("pageSize", pageSize);
    const url = '/api/api/cms/article/open/banner/list'
    return request.post(url, parmas)
}

// 新闻列表
function listNews(pageNum, pageSize,categoryId,title) {
    const parmas = new URLSearchParams();
    parmas.append("pageNum", pageNum);
    parmas.append("pageSize", pageSize);
    parmas.append("categoryId", categoryId);
    parmas.append("title",title)
    const url = '/api/api/cms/article/open/list'
    return request.post(url, parmas)
}
//获取音乐
function  getmusic() {
    const url = `/api/music-api/top/song?type=96`;
    return request.get(url);
}
//获取音乐url
function getsongUrl(songid) {
    const url = `/api/music-api/song/url?id=${songid}`;
    return request.get(url);
}
//获取最新mv
function getMusicMv() {
    const url = `/api/music-api/mv/first?limit=100`
    return request.get(url);

}
//获取mv地址
function getMvUrl(id) {
    const url = `/api/music-api/mv/url?id=${id}`
    return request.get(url)
}
//注册
function getresiger(loginName,code,phonenumber,password,userName) {
    const url =  `/api/api/registry`;
    const params = new URLSearchParams();
    params.append("loginName",loginName);
    params.append("code",code);
    params.append("phonenumber",phonenumber);
    params.append("password",password);
    params.append("userName",userName);
    params.append("sex",0);
    return request.post(url,params)
}
//短信验证码
function getvcode(mobile) {
    const url = `/api/api/short-message/vcode/${mobile}`
    return request.get(url)

}
//忘记密码
function getForget(loginName,code,phonenumber,password) {
    const url =  `/api/api/password/forget`;
    const params = new URLSearchParams();
    params.append("loginName",loginName);
    params.append("code",code);
    params.append("phonenumber",phonenumber);
    params.append("password",password);
    return request.post(url,params)
}
//登录
function getLogin(username,password,rememberMe=true) {
    const url =  `/api/api/login`;
    const params = new URLSearchParams();
    params.append("username",username);
    params.append("rememberMe",rememberMe);
    params.append("password",password);
    return request.post(url,params)
}
//获取个人信息
function getusertInfo() {
    const url = `/api/api/login-user/info`;
    return request.get(url);
}
//上传图片
function getimg(file,fileUseForEnum="BBS") {
    const url = `/api/api/nos/upload/image`;
    const params = new FormData();
    params.append("file",file);
    params.append("fileUseForEnum",fileUseForEnum);
    return request.post(url,params);
}
//修改头像
function getheaderImg(file) {
    const url = `/api/api/system/user/profile/update/avatar/nos`;
    const params = new FormData();
    params.append("avatarfile",file);
    return request.post(url,params)

}
//新闻详情
function newsDetails(articleId) {
    const url = `/api/api/cms/article/open/detail/${articleId}`
    return request.get(url)
}
//热门新闻列表
function hotNewsList(pageNum,pageSize) {
    const parmas = new URLSearchParams();
    parmas.append("pageNum", pageNum);
    parmas.append("pageSize", pageSize);
    const url = '/api/api/cms/article/open/hot/list'
    return request.post(url,parmas)
}
//修改个人信息
function changeUserInfo(userName,email,phonenumber,remark) {
    const url =  `/api/api/system/user/profile/update`;
    const params = new URLSearchParams();
    params.append("userName",userName);
    params.append("email",email);
    params.append("remark",remark);
    params.append("phonenumber",phonenumber);
    return request.post(url,params)
}
//退出登录
function getloginout() {
    const url = "/api/api/logout";
    return request.get(url);
}
//收藏功能
function getCollect(articleId) {
    const url = `/api/api/cms/collect/collect/article/${articleId}`;
    return request.get(url)
}
//收藏列表
function getCollectList() {
    const url = `/api/api/cms/article/collect/list`;
    return request.get(url);

}
//增加阅读量
function addSee(id) {
    const url = `/api/api/cms/article/open/add/read-num/${id}`;
    return request.get(url);

}
//点赞
function getZan(articleId) {
    const url = `/api/api/cms/article/add/zan/${articleId}`;
    return request.get(url);
}
//订阅
function Subscribe(categoryIds) {
    const url = `/api/api/cms/userCategory/subscription/category`;
    const params = new URLSearchParams();
    params.append("categoryIds",categoryIds);
    return request.post(url,params)
}
//订阅列表
function getSubscribe() {
    const url = `/api/api/cms/category/subscription/list`;
    return request.get(url)

}
export {
    getClassification,newsList,newsClassList,shufflingFigure,listNews,
    getmusic,
    getsongUrl,
    getresiger,
    getvcode,
    getForget,
    getLogin,
    getusertInfo,
    getimg,
    getheaderImg,
    newsDetails,
    hotNewsList,
    changeUserInfo,
    getloginout,
    getCollect,
    getCollectList,
    addSee,
    getZan,
    Subscribe,
    getSubscribe,
    getMusicMv,
    getMvUrl
}